<?php
/**
*
* @author moltendorf (Matthew Oltendorf) moltendorf@gmail.com
* @package umil
* @version $Id install_molten_chat.php 2.1.0-a2 2009-07-26 20:34:59GMT moltendorf $
* @copyright (c) 2009 Matthew Oltendorf
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/info_acp_molten');

if (!file_exists($phpbb_root_path . 'umil/umil.' . $phpEx))
{
	trigger_error('Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
}

// We only allow a founder to install this MOD
if ($user->data['user_type'] != USER_FOUNDER)
{
	if ($user->data['user_id'] == ANONYMOUS)
	{
		login_box('', 'LOGIN');
	}

	trigger_error('NOT_AUTHORISED');
}

if (!class_exists('umil'))
{
	include($phpbb_root_path . 'umil/umil.' . $phpEx);
}

$umil = new umil(true);

$mod = array(
	'name'		=> 'MoltX QuickChat 2.1 for phpBB 3',
	'version'	=> '2.1.0-a2',
	'config'	=> 'molten_chat_version',
	'enable'	=> 'molten_chat_enable',
);

if (confirm_box(true))
{
	// Install the base 2.1.0-a2 version
	if (!$umil->config_exists($mod['config']))
	{
		// We must handle the version number ourselves.
		$umil->config_add($mod['config'], $mod['version']);

		$umil->permission_add(array(
			array('a_molten_x_settings', 1),
			array('a_molten_chat_settings', 1),
			array('m_molten_chat_moderate_chat', 1),
			array('u_molten_chat_user_view', 1),
			array('u_molten_chat_user_send', 1),
			array('u_molten_chat_user_view_moderated', 1),
			array('u_molten_chat_user_send_moderated', 1),
		));

		$umil->permission_set(array(
			array('ROLE_ADMIN_FULL', 'a_molten_chat_settings', 'role'),
			array('ROLE_USER_FULL', 'u_molten_chat_user_send', 'role'),
			array('ROLE_USER_STANDARD', 'u_molten_chat_user_send', 'role'),
			array('ROLE_USER_NOPM', 'u_molten_chat_user_send', 'role'),
			array('ROLE_USER_NOAVATAR', 'u_molten_chat_user_send', 'role'),
			array('ADMINISTRATORS', 'u_molten_chat_user_send', 'group'),
			array('REGISTERED', 'u_molten_chat_user_send', 'group')
		));

		$umil->config_add('molten_chat_installed', '1', '0');

		$umil->module_add(array(
			// Add "MoltX" tab.
			array('acp', 0, 'MOLTEN_X'),

			// Add "QuickChat" category to "MoltX" tab.
			array('acp', 'MOLTEN_X', 'MOLTEN_CHAT'),

			// Add "QuickChat Settings" module to "QuickChat" category.
			array('acp', 'MOLTEN_CHAT',
				array(
					'module_basename'	=> 'molten_chat',
					'module_langname'	=> 'MOLTEN_CHAT_SETTINGS',
					'module_mode'		=> 'settings',
					'module_auth'		=> 'acl_a_molten_chat_settings'
				)
			)
		));

		// Our final action, we purge the board cache.
		$umil->cache_purge('template');
		$umil->cache_purge('theme');
		$umil->cache_purge();
	}

	// We are done
	trigger_error('MOLTEN_CHAT_INSTALLED');
}
else
{
	confirm_box(false, 'INSTALL_MOLTEN_CHAT');
}

// Shouldn't get here.
redirect($phpbb_root_path . $user->page['page_name']);


?>